package org.zlb.netty.client.marshalling;

import org.zlb.netty.server.marshalling.ReceiveResponse;
import org.zlb.netty.server.marshalling.SendRequest;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class MarshallingClientHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        for (int i=0; i<10; i++) {
        	SendRequest send = new SendRequest();
            send.setId(i);
            send.setMessage("message"+i);
            send.setName("name"+i);
            
            ctx.write(send);
        }
        ctx.flush();
    }
    
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
            throws Exception {
        cause.printStackTrace();
    }
  
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg)throws Exception {
    	ReceiveResponse receive = (ReceiveResponse) msg;
        System.out.println("server反馈："+receive);
    }
}
